package com.mccken.demo.proxy.cglib.cglib2;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;

/**
 * @program: mccken-collect
 * @description:
 * @author: mccken
 * @create: 2022-11-01 16:19
 **/
public class CglibProxyCreator {
	
	private Object target;
	
	private MethodInterceptor methodInterceptor;
	
	public CglibProxyCreator(Object target, MethodInterceptor methodInterceptor) {
		this.target = target;
		this.methodInterceptor = methodInterceptor;
	}
	
	public Object getProxy() {
		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(target.getClass());
		enhancer.setCallback(methodInterceptor);
		return enhancer.create();
	}
	
}
